﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Travel.API.DataBase;
using Travel.API.Models;

namespace Travel.API.Services
{
    public class TouristRouteServices : ITouristRouteServices
    {
        private readonly AppDbContext _dd;
        public TouristRouteServices(AppDbContext dd)
        {
            _dd = dd;
        }
        public IEnumerable<TouristRoute> GetTouristRoutes(string keyword, string RatingOperator, int? RatingValue)
        {

            IQueryable<TouristRoute> result =
                _dd.
                TouristRoute.
                Include(z => z.TouristRoutePhoto);

            if (!string.IsNullOrWhiteSpace(keyword))
            {
                keyword = keyword.Trim();
                result = result.Where(t => t.Title.Contains(keyword));
            }
            if (RatingValue >= 0)
            {
                result = RatingOperator switch
                {
                     "largerThan" => result.Where(t=>t.Rating>=RatingValue),
                     "lessThan" => result.Where(t => t.Rating <= RatingValue),
                    _ => result.Where(t => t.Rating == RatingValue),
                 };
            }

            var data = result.ToList();

            return result.ToList();

        }

        public TouristRoute GetTouristRoutes(Guid TouristRouteId)
        {
            return _dd.TouristRoute.Include(z => z.TouristRoutePhoto).FirstOrDefault(z => z.ID == TouristRouteId);

        }

        public IEnumerable<TouristRoutePhoto> GetTouristRoutesIdByPhoto(Guid TouristRouteId)
        {
            return _dd.TouristRoutePhoto.Where(z => z.TouristRouteId == TouristRouteId);
        }

        public bool TouristRoutesExistence(Guid TouristRouteId)
        {
            return _dd.TouristRoute.Any(x => x.ID == TouristRouteId);
        }
    }
}
